from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-19 14:04:26.942245
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 19, Jan, 2022
Time: 14:04:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7672
Nobs: 541.000 HQIC: -48.2021
Log likelihood: 6295.42 FPE: 8.80617e-22
AIC: -48.4815 Det(Omega_mle): 7.46790e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.367461 0.070735 5.195 0.000
L1.Burgenland 0.102137 0.042771 2.388 0.017
L1.Kärnten -0.113640 0.022115 -5.139 0.000
L1.Niederösterreich 0.191060 0.088981 2.147 0.032
L1.Oberösterreich 0.121550 0.088217 1.378 0.168
L1.Salzburg 0.263706 0.045163 5.839 0.000
L1.Steiermark 0.026274 0.059530 0.441 0.659
L1.Tirol 0.106855 0.048004 2.226 0.026
L1.Vorarlberg -0.076225 0.042452 -1.796 0.073
L1.Wien 0.017455 0.078241 0.223 0.823
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067066 0.154198 0.435 0.664
L1.Burgenland -0.044441 0.093238 -0.477 0.634
L1.Kärnten 0.040355 0.048210 0.837 0.403
L1.Niederösterreich -0.204017 0.193972 -1.052 0.293
L1.Oberösterreich 0.450205 0.192307 2.341 0.019
L1.Salzburg 0.286688 0.098451 2.912 0.004
L1.Steiermark 0.111175 0.129771 0.857 0.392
L1.Tirol 0.307959 0.104646 2.943 0.003
L1.Vorarlberg 0.020452 0.092542 0.221 0.825
L1.Wien -0.026276 0.170561 -0.154 0.878
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196398 0.036093 5.441 0.000
L1.Burgenland 0.091215 0.021824 4.180 0.000
L1.Kärnten -0.007566 0.011285 -0.670 0.503
L1.Niederösterreich 0.235623 0.045403 5.190 0.000
L1.Oberösterreich 0.165958 0.045014 3.687 0.000
L1.Salzburg 0.039741 0.023045 1.725 0.085
L1.Steiermark 0.025116 0.030376 0.827 0.408
L1.Tirol 0.082066 0.024495 3.350 0.001
L1.Vorarlberg 0.054296 0.021661 2.507 0.012
L1.Wien 0.118779 0.039923 2.975 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121689 0.036173 3.364 0.001
L1.Burgenland 0.042018 0.021873 1.921 0.055
L1.Kärnten -0.014168 0.011310 -1.253 0.210
L1.Niederösterreich 0.173461 0.045504 3.812 0.000
L1.Oberösterreich 0.334338 0.045113 7.411 0.000
L1.Salzburg 0.102212 0.023096 4.426 0.000
L1.Steiermark 0.109330 0.030443 3.591 0.000
L1.Tirol 0.091307 0.024549 3.719 0.000
L1.Vorarlberg 0.056892 0.021709 2.621 0.009
L1.Wien -0.017477 0.040012 -0.437 0.662
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112968 0.068442 1.651 0.099
L1.Burgenland -0.042266 0.041384 -1.021 0.307
L1.Kärnten -0.045459 0.021398 -2.124 0.034
L1.Niederösterreich 0.142053 0.086096 1.650 0.099
L1.Oberösterreich 0.167678 0.085357 1.964 0.049
L1.Salzburg 0.280687 0.043698 6.423 0.000
L1.Steiermark 0.063936 0.057600 1.110 0.267
L1.Tirol 0.154537 0.046448 3.327 0.001
L1.Vorarlberg 0.094388 0.041075 2.298 0.022
L1.Wien 0.075335 0.075705 0.995 0.320
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.092160 0.053253 1.731 0.084
L1.Burgenland 0.019551 0.032200 0.607 0.544
L1.Kärnten 0.052299 0.016650 3.141 0.002
L1.Niederösterreich 0.191424 0.066990 2.858 0.004
L1.Oberösterreich 0.323563 0.066415 4.872 0.000
L1.Salzburg 0.039091 0.034001 1.150 0.250
L1.Steiermark -0.002190 0.044817 -0.049 0.961
L1.Tirol 0.124424 0.036140 3.443 0.001
L1.Vorarlberg 0.063260 0.031960 1.979 0.048
L1.Wien 0.097703 0.058904 1.659 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163402 0.064484 2.534 0.011
L1.Burgenland 0.009112 0.038991 0.234 0.815
L1.Kärnten -0.065220 0.020161 -3.235 0.001
L1.Niederösterreich -0.108594 0.081118 -1.339 0.181
L1.Oberösterreich 0.216914 0.080422 2.697 0.007
L1.Salzburg 0.049739 0.041172 1.208 0.227
L1.Steiermark 0.254536 0.054269 4.690 0.000
L1.Tirol 0.497076 0.043762 11.359 0.000
L1.Vorarlberg 0.065851 0.038700 1.702 0.089
L1.Wien -0.078766 0.071327 -1.104 0.269
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165634 0.071343 2.322 0.020
L1.Burgenland -0.009212 0.043138 -0.214 0.831
L1.Kärnten 0.062534 0.022305 2.804 0.005
L1.Niederösterreich 0.177087 0.089745 1.973 0.048
L1.Oberösterreich -0.065413 0.088975 -0.735 0.462
L1.Salzburg 0.206968 0.045550 4.544 0.000
L1.Steiermark 0.136490 0.060041 2.273 0.023
L1.Tirol 0.056023 0.048416 1.157 0.247
L1.Vorarlberg 0.143540 0.042816 3.352 0.001
L1.Wien 0.129444 0.078913 1.640 0.101
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395256 0.041690 9.481 0.000
L1.Burgenland -0.003338 0.025208 -0.132 0.895
L1.Kärnten -0.020761 0.013034 -1.593 0.111
L1.Niederösterreich 0.202801 0.052443 3.867 0.000
L1.Oberösterreich 0.241220 0.051993 4.639 0.000
L1.Salzburg 0.034279 0.026618 1.288 0.198
L1.Steiermark -0.016953 0.035086 -0.483 0.629
L1.Tirol 0.087187 0.028293 3.082 0.002
L1.Vorarlberg 0.050177 0.025020 2.005 0.045
L1.Wien 0.033825 0.046114 0.734 0.463
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.033914 0.099871 0.165265 0.136906 0.087467 0.083565 0.029979 0.211622
Kärnten 0.033914 1.000000 -0.026523 0.133483 0.048194 0.083989 0.447206 -0.069765 0.093515
Niederösterreich 0.099871 -0.026523 1.000000 0.308763 0.124085 0.265333 0.065706 0.158373 0.280056
Oberösterreich 0.165265 0.133483 0.308763 1.000000 0.217181 0.292953 0.172171 0.134666 0.233460
Salzburg 0.136906 0.048194 0.124085 0.217181 1.000000 0.128345 0.085472 0.107924 0.127087
Steiermark 0.087467 0.083989 0.265333 0.292953 0.128345 1.000000 0.138609 0.104878 0.029088
Tirol 0.083565 0.447206 0.065706 0.172171 0.085472 0.138609 1.000000 0.066149 0.150339
Vorarlberg 0.029979 -0.069765 0.158373 0.134666 0.107924 0.104878 0.066149 1.000000 -0.004607
Wien 0.211622 0.093515 0.280056 0.233460 0.127087 0.029088 0.150339 -0.004607 1.000000